package com.fick.tags;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.hibernate.dao.NewsDAO;
import com.fick.hibernate.model.News;
/**
 * 前台页面新闻列表显示标签
 * 
 * 
 * **/
public class NewsListTopTag extends TagSupport {
	private static Log log = LogFactory.getLog(NewsListTopTag.class);
	
	public int doStartTag() throws JspException {
			
		try {
			StringBuffer sb = new StringBuffer();
			
			NewsDAO newsDAO = new NewsDAO();
			String hql1 = "";
			String hql2 = "";
			String hql3 = "";
			String hql4 = "";
			String hql5 = "";
			int temp=0;
			if(typeid!=null&&!typeid.equals("")&&!typeid.equals("null"))
			{
				hql1 = " where typeid = "+typeid;temp++;
			}
			if(bigclassid!=null&&!bigclassid.equals("")&&!bigclassid.equals("null"))
			{
				hql2 = " and bigclassid = "+bigclassid;temp++;
			}
			if(smallclassid!=null&&!smallclassid.equals("")&&!smallclassid.equals("null"))
			{
				hql3 = " and smallclassid = "+smallclassid;temp++;
			}
			/*if(temp == 0)
			{
				hql4 = " where isAss='1' and typeid!='11'";//大桥局的特殊需求 首页显示所有新闻时 不能显示报价信息
			}
		
			else
			{
				hql4 = " and isAss='1'";
			}*/
			hql4 = " and isAss='1'";
			String hql = "";
			String tophql = "";
			if(isshowTop.trim().equals("1"))
			{
				hql =hql1+hql2+hql3+hql4+" order by isTop desc, addDate desc ";
			}
			else
			{
				hql=hql1+hql2+hql3+hql4+" and isTop!='1' order by addDate desc ";
				tophql=hql1+hql2+hql3+hql4+" and isTop='1' order by addDate desc ";
			}
	
			List newsTopList = null;
			
			if(!isshowTop.trim().equals("1"))
			{
				newsTopList = newsDAO.findPageByHql(tophql, 1, 1);
			}
			
			if(newsTopList != null && newsTopList.size()!=0 && smallclassid!=null && !"".equals(smallclassid.trim())&&!"0".equals(smallclassid.trim()))
			{
				News news = new News();
				for(int i = 0 ; i< newsTopList.size() ; i++)
				{
					news = (News)newsTopList.get(i);
					sb.append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
					sb.append("<tr>");
		            sb.append("<td class='list_tit'>");
		            sb.append("<a href='"+title_href+"?newid="+news.getNewId());
					if(typeid!=null&&!typeid.equals(""))
					{
						sb.append("&typeid="+typeid);
					}
					/*else if(news.getTypeid()!=null&&news.getTypeid()!=0)
					{
						sb.append("&typeid="+news.getTypeid());
					}
					if(bigclassid!=null&&!bigclassid.equals(""))
					{
						sb.append("&bigclassid="+bigclassid);
					}
					else if(news.getBigclassid()!=null&&news.getBigclassid()!=0)
					{
						sb.append("&bigclassid="+news.getBigclassid());
					}
					if(smallclassid!=null&&!smallclassid.equals(""))
					{
						sb.append("&smallclassid="+smallclassid);
					}
					else if(news.getSmallclassid()!=null&&news.getBigclassid()!=0)
					{
						sb.append("&smallclassid="+news.getSmallclassid());
					}*/
					sb.append("'>"+news.getTitle()+"</a>");
		            sb.append("</td>");
		            sb.append("</tr>");
		            sb.append("<tr>");
					sb.append("<td>&nbsp;</td>");
					sb.append("</tr>");
		            sb.append("</table>");
				}
			}
			
			JspWriter out = pageContext.getOut();
			out.println(sb.toString());
			out.flush();
		}catch(IOException e)
		{
			log.error("标签显示错误"+e);
			e.printStackTrace();
		}
		return SKIP_BODY;
	}
	
	private String typeid = "";		//一级菜单 id
	
	private String bigclassid = "";		//二级菜单 id
	
	private String smallclassid = "";	//三级菜单 id
	
	private String td_width = "";		//td 宽
	
	private String td_height = "";		//td 高
	
	private String valign = "";			//td对齐方式
	
	private String align = "";			//td对齐方式
	
	private String td_class = "";		//td样式
	
	private String nowpage = "1";		//当前显示页数
	
	private String pagesize = "20";		//一页多少条记录
	
	private String img_src = "";		//头图片
	
	private String img_height = "";		//头图片长
	
	private String img_width = "";		//头图片宽
	
	private String img_class = "";		//图片td样式
	
	private String date_height = "";	//日期td长
	
	private String date_width = "";		//日期td宽
	
	private String date_class = "";		//日期td样式
	
	private String url = "";			//标题链接页面
	
	private String isshowDate = "true";	//是否显示日期
	
	private String title_href="";	//链接
	
	private String date_font_class = "";	//日期字体样式
	
	private String title_length="18";
	
	private String tr_split = "1";
	
	private String isshowTop = "1";
	
	public static Log getLog() {
		return log;
	}

	public static void setLog(Log log) {
		NewsListTopTag.log = log;
	}

	public String getTypeid() {
		return typeid;
	}

	public void setTypeid(String typeid) {
		this.typeid = typeid;
	}

	public String getBigclassid() {
		return bigclassid;
	}

	public void setBigclassid(String bigclassid) {
		this.bigclassid = bigclassid;
	}

	public String getSmallclassid() {
		return smallclassid;
	}

	public void setSmallclassid(String smallclassid) {
		this.smallclassid = smallclassid;
	}

	public String getTd_width() {
		return td_width;
	}

	public void setTd_width(String td_width) {
		this.td_width = td_width;
	}

	public String getTd_height() {
		return td_height;
	}

	public void setTd_height(String td_height) {
		this.td_height = td_height;
	}

	public String getValign() {
		return valign;
	}

	public void setValign(String valign) {
		this.valign = valign;
	}

	public String getTd_class() {
		return td_class;
	}

	public void setTd_class(String td_class) {
		this.td_class = td_class;
	}

	public String getAlign() {
		return align;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public String getNowpage() {
		return nowpage;
	}

	public void setNowpage(String nowpage) {
		this.nowpage = nowpage;
	}

	public String getPagesize() {
		return pagesize;
	}

	public void setPagesize(String pagesize) {
		this.pagesize = pagesize;
	}

	public String getImg_src() {
		return img_src;
	}

	public void setImg_src(String img_src) {
		this.img_src = img_src;
	}

	public String getImg_height() {
		return img_height;
	}

	public void setImg_height(String img_height) {
		this.img_height = img_height;
	}

	public String getImg_width() {
		return img_width;
	}

	public void setImg_width(String img_width) {
		this.img_width = img_width;
	}

	public String getDate_height() {
		return date_height;
	}

	public void setDate_height(String date_height) {
		this.date_height = date_height;
	}

	public String getDate_width() {
		return date_width;
	}

	public void setDate_width(String date_width) {
		this.date_width = date_width;
	}

	public String getDate_class() {
		return date_class;
	}

	public void setDate_class(String date_class) {
		this.date_class = date_class;
	}

	public String getImg_class() {
		return img_class;
	}

	public void setImg_class(String img_class) {
		this.img_class = img_class;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getIsshowDate() {
		return isshowDate;
	}

	public void setIsshowDate(String isshowDate) {
		this.isshowDate = isshowDate;
	}

	public String getTitle_href() {
		return title_href;
	}

	public void setTitle_href(String title_href) {
		this.title_href = title_href;
	}

	public String getDate_font_class() {
		return date_font_class;
	}

	public void setDate_font_class(String date_font_class) {
		this.date_font_class = date_font_class;
	}

	public String getTitle_length() {
		return title_length;
	}

	public void setTitle_length(String title_length) {
		this.title_length = title_length;
	}

	public String getTr_split() {
		return tr_split;
	}

	public void setTr_split(String tr_split) {
		this.tr_split = tr_split;
	}

	public String getIsshowTop() {
		return isshowTop;
	}

	public void setIsshowTop(String isshowTop) {
		this.isshowTop = isshowTop;
	}
	
}
